function t(t, a, e) {
    return a in t ? Object.defineProperty(t, a, {
        value: e,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : t[a] = e, t;
}

require("../wxSearch/wxSearch.js");

var a = require("../../../utils/qqmap-wx-jssdk.js"), e = require("../../../utils/util.js"), i = (new a({
    key: "BQQBZ-W6IWG-R36QO-IU64E-SWL46-2EBTD"
}), getApp()), o = i.globalData.url, s = {
    LOCATION: 1,
    MARKER: 2
}, n = {
    MAX: 18,
    MIN: 5,
    DEFAULT: 12
};

Page({
    data: {
        domain: o,
        dataList: [],
        latitude: 32.02227,
        longitude: 118.86482,
        scale: n.DEFAULT,
        markers: [],
        markerLat: [],
        types: 1,
        pageNum: 1,
        isFromSearch: !0,
        searchLoading: !1,
        searchLoadingComplete: !1
    },
    onLoad: function(t) {
        var a = this;
        if (a.getCurrentLocation(), void 0 !== t.searchValue) {
            var o = t.searchValue, s = t.types;
            a.setData({
                types: s
            });
        } else a.setData({
            types: 2
        });
        var s = a.data.types, n = i.globalData.token;
        o ? 2 == s ? (wx.setNavigationBarTitle({
            title: "美容养护"
        }), e.request(i, "wx/biz/getBizShopsByShopName", "GET", {
            shopName: o,
            token: n
        }, function(t) {
            0 == t.data.length ? (wx.showToast({
                title: "没有搜索到符合门店",
                icon: "none"
            }), a.setData({
                searchLoadingComplete: !0
            })) : (a.setData({
                dataList: t.data,
                searchLoading: !0
            }), a.showStores(t.data));
        }, function(t) {})) : (wx.setNavigationBarTitle({
            title: "搜索的商铺"
        }), e.request(i, "wx/biz/getBizShopsByShopName", "POST", {
            shopName: o,
            token: n
        }, function(t) {
            0 == t.data.length ? (wx.showToast({
                title: "没有搜索到符合门店",
                icon: "none"
            }), a.setData({
                searchLoadingComplete: !0
            })) : (a.setData({
                dataList: t.data,
                searchLoading: !0
            }), a.showStores(t.data));
        }, function(t) {})) : 2 == s ? (a.fetchList(), wx.setNavigationBarTitle({
            title: "美容养护"
        })) : (a.setData({
            dataList: []
        }), wx.setNavigationBarTitle({
            title: "搜索的商铺"
        }));
    },
    onReady: function() {},
    onShow: function() {
        this.setData({
            scale: n.DEFAULT
        }), this.mapCtx = wx.createMapContext("storeMap"), this.getCurrentLocation();
    },
    fetchList: function(t) {
        var a = this, o = this.data.latitude, s = this.data.longitude, n = this.data.pageNum, r = i.globalData.token;
        e.request(i, "wx/biz/nearbyShops", "POST", {
            latitude: o,
            longitude: s,
            pageNum: n,
            types: 2,
            token: r
        }, function(e) {
            if (1 == a.data.onPullDownRefresh && a.success(), a.data.dataList.length > 3) if (e.data.length > 0) {
                var i = !(e.data.length > 2);
                a.setData({
                    dataList: t ? e.data : a.data.dataList.concat(e.data),
                    searchLoading: i,
                    searchLoadingComplete: !0
                });
            } else a.setData({
                searchLoadingComplete: !0,
                searchLoading: !1
            }); else e.data.length > 0 && a.setData({
                dataList: t ? e.data : a.data.dataList.concat(e.data),
                searchLoadingComplete: !0,
                searchLoading: !1
            });
            a.showStores(e);
        }, function(t) {});
    },
    onReachBottom: function() {
        var t = this;
        this.setData({
            pageNum: t.data.pageNum + 1
        }), this.fetchList();
    },
    onPullDownRefresh: function() {
        var t = this;
        t.setData({
            pageNum: 1
        }), t.fetchList(!0), wx.showNavigationBarLoading(), setTimeout(function() {
            wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
        }, 1500);
    },
    setControls: function() {
        var t = this;
        wx.getSystemInfo({
            success: function(a) {
                t.setData({
                    controls: [ {
                        id: s.MARKER,
                        iconPath: "../../../image/store_marker.png",
                        position: {
                            left: a.windowWidth / 2 - 11,
                            top: a.windowHeight / 2 - 35,
                            width: 42,
                            height: 42
                        },
                        clickable: !1
                    } ]
                });
            }
        });
    },
    getCurrentLocation: function() {
        var t = this;
        wx.getLocation({
            success: function(a) {
                t.setData({
                    latitude: a.latitude,
                    longitude: a.longitude
                });
            }
        });
    },
    controltap: function(t) {
        t.controlId === s.LOCATION && this.mapCtx.moveToLocation();
    },
    showStores: function(t) {
        t.data.length ? this.setMarkers(t.data) : wx.showToast({
            title: "全部加载"
        });
    },
    setMarkers: function(t) {
        for (var a = this, i = this.data.markers, o = [], s = "", n = 0; n < t.length; n++) o.push({
            id: t[n].latitude + "," + t[n].longitude + ";"
        });
        for (var r = 0; r < o.length; r++) s += o[r].id;
        s = s.substring(0, s.length - 1), e.transformatLat({
            locations: s,
            type: 3,
            key: "HVLBZ-Q24C2-CO6U2-C3AUW-EH4E6-D3F6X"
        }, function(e) {
            a.setData({
                markerLat: a.data.markerLat.concat(e.locations)
            });
            for (var o = 0; o < t.length; o++) {
                var s = a.data.markerLat[o].lat, n = a.data.markerLat[o].lng;
                i.push({
                    id: t[o].shopId,
                    latitude: s,
                    longitude: n,
                    shop: t[o].distance,
                    title: t[o].shopName,
                    iconPath: "/image/store.png",
                    width: 50,
                    height: 50,
                    callout: {
                        content: t[o].shopName,
                        color: "#ffffff",
                        fontSize: 14,
                        borderRadius: 16,
                        bgColor: "#262930",
                        padding: 8
                    }
                }), a.setData({
                    markers: i
                });
            }
        }, function(t) {});
    },
    moveMarker: function(a) {
        var e;
        wx.pageScrollTo ? wx.pageScrollTo({
            scrollTop: 0
        }) : wx.showModal({
            title: "提示",
            content: "当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。"
        });
        var i = this, o = a.currentTarget.id, s = "markers[" + [ o ] + "].iconPath", n = "markers[" + [ this.data.iconNum ] + "].iconPath";
        this.data.iconNum && i.setData(t({}, n, "/image/store.png")), this.mapCtx.includePoints({
            padding: [ 80 ],
            points: [ {
                latitude: this.data.markers[o].latitude,
                longitude: this.data.markers[o].longitude
            }, {
                latitude: this.data.latitude,
                longitude: this.data.longitude
            } ]
        }), i.setData((e = {}, t(e, s, "/image/store_marker.png"), t(e, "iconNum", o), e));
    },
    bindto: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/pages/home/detail/detail?id=" + a
        });
    },
    wxSearchTab: function() {
        var t = this;
        wx.redirectTo({
            url: "/pages/home/youhui/search/search?types=" + t.data.types
        });
    }
});